use rocket_contrib::json::Json;
use rocket::response::Responder;
use serde::Serialize;

const CODE_SUCCESS: &str = "0";
const MSG_SUCCESS: &str = "success";


#[derive(Serialize)]
pub struct Wrapper<T: Serialize> {
    data: T,
    code: &'static str,
    msg: &'static str,
}

#[derive(Serialize)]
pub struct WrapperNoData {
    code: &'static str,
    msg: &'static str,
}

pub struct Action;

impl Action {
    pub fn ok<T: Serialize>(t: T) -> impl Responder<'static> {
        Json(Wrapper {
            data: t,
            code: CODE_SUCCESS,
            msg: MSG_SUCCESS,
        })
    }

    pub fn empty() -> impl Responder<'static> {
        Json(WrapperNoData {
            code: CODE_SUCCESS,
            msg: MSG_SUCCESS,
        })
    }
}